package 复习.面试TOP101.二分查找和排序;

public class 二分查找_1 {
    public int search (int[] nums, int target) {
        // write code here
        int i = 0;
        int j = nums.length - 1;
        while(i <= j){
            int index = i + ((j - i) >> 1);
            if(nums[index] > target){
                j = index - 1;
            }else if(nums[index] < target){
                i = index + 1;
            }else{
                return index;
            }
        }
        return -1;
    }
}
